﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furion.CMS.Domain
{
    /// <summary>
    /// 白名单
    /// </summary>
    [SuppressChangedListener]
    public class Whitelist : Entity, IEntityTypeBuilder<Whitelist>
    {
        public Whitelist()
        {
            this.CreatedTime = DateTimeOffset.UtcNow;
        }

        /// <summary>
        /// 主机地址
        /// </summary>
        [MaxLength(100), Required]
        public string HostAddress { get; set; }

        /// <summary>
        /// 请求源地址
        /// </summary>
        [MaxLength(200)]
        public string RefererUrl { get; set; }

        /// <summary>
        /// 描述信息
        /// </summary>
        [MaxLength(400)]
        public string Description { get; set; }

        /// <summary>
        /// 白名单关联的通行证集合
        /// </summary>
        public virtual ICollection<UserPassport> Passports { get; set; }

        public void Configure(EntityTypeBuilder<Whitelist> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.UseDefaultTableNameDefine();

            entityBuilder.HasIndex(p => new { p.HostAddress, p.RefererUrl });
        }
    }
}
